package vip.meeet.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;


@Component
public class DataComponent implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        DataComponent.applicationContext = applicationContext;
    }

    public static DataComponent getInstance() {
        return applicationContext.getBean(DataComponent.class);
    }

    @PostConstruct
    public void initData() {
        System.out.println("init data");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("destroy...");
    }
}
